package com.sina.weibo;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import com.sina.weibo.models.Account;
import com.sina.weibo.models.UnreadNum;
import com.sina.weibo.models.User;
import java.io.File;
import java.util.List;

public class WeiboEventService extends Service
{
  public static final String KEY_NOTIFY = "NOTIFY_KEY";
  public static final int NOTIFY_AT = 10003;
  public static final int NOTIFY_COMMENT = 10001;
  public static final int NOTIFY_FANS = 10004;
  public static final int NOTIFY_HOME = 10000;
  public static final int NOTIFY_MESSAGE = 10002;
  public static final String UNREAD_COUNT_EXTRA_NAME = "NUM";
  private final int AT;
  private final int COMMENT;
  private final int FANS;
  private final int HOME;
  private final int MESSAGE;
  private WeiboRemoteSerivcePoxy binder;
  private String mCacheDir;
  private CheckStatusHandler mCheckStatusHandler;
  private int mNotifyID;
  private int mNotifyMode;
  private String mPassword;
  private int mPrefInterval;
  private BroadcastReceiver mReceiver;
  private boolean mTaskFree = 0;
  private User mUser;
  private String mUsername;
  private NotificationManager ntfmngr;

  public WeiboEventService()
  {
    CheckStatusHandler localCheckStatusHandler = new CheckStatusHandler();
    this.mCheckStatusHandler = localCheckStatusHandler;
    this.HOME = 0;
    this.COMMENT = 1;
    this.MESSAGE = 2;
    this.AT = 3;
    this.FANS = 4;
    this.mNotifyMode = 0;
    this.mNotifyID = -1;
    WeiboEventService.1 local1 = new WeiboEventService.1(this);
    this.mReceiver = local1;
  }

  private void delNotify()
  {
    if (this.ntfmngr != null)
      this.ntfmngr.cancelAll();
  }

  private void dispatchMessage(UnreadNum paramUnreadNum)
  {
    String[] arrayOfString;
    int i;
    int j;
    if (paramUnreadNum != null)
    {
      arrayOfString = new String[5];
      i = -1;
      j = 0;
      if (j < 5);
    }
    else
    {
      CheckStatusHandler localCheckStatusHandler = this.mCheckStatusHandler;
      long l = MainTabActivity.mPrefInterval;
      localCheckStatusHandler.next(l);
      return;
    }
    arrayOfString[j] = "";
    switch (j)
    {
    default:
    case 0:
    case 1:
    case 3:
    case 2:
    case 4:
    }
    do
    {
      do
      {
        do
        {
          do
          {
            do
            {
              if (arrayOfString[j].length() > 0)
              {
                String str1 = arrayOfString[j];
                setMessageBox(str1, i);
              }
              j += 1;
              break;
            }
            while (!MainTabActivity.mPrefNotifyNewblog);
            String str2 = String.valueOf(arrayOfString[j]);
            localStringBuilder = new StringBuilder(str2);
            Object[] arrayOfObject1;
            if (paramUnreadNum.mblog > 0)
            {
              arrayOfObject1 = new Object[2];
              Integer localInteger1 = Integer.valueOf(paramUnreadNum.mblog);
              arrayOfObject1[0] = localInteger1;
              String str3 = getString(2131427383);
              arrayOfObject1[1] = str3;
            }
            for (str4 = String.format("%d %s", arrayOfObject1); ; str4 = "")
            {
              String str5 = str4;
              arrayOfString[j] = str5;
              if (i > 0)
              {
                Intent localIntent1 = new Intent("com.sina.weibo.action.HOMENEW");
                Intent localIntent2 = localIntent1.putExtra("NUM", i);
                sendBroadcast(localIntent1);
              }
              i = paramUnreadNum.mblog;
              this.mNotifyID = j;
              break;
            }
          }
          while (!MainTabActivity.mPrefNotifyComment);
          String str6 = String.valueOf(arrayOfString[j]);
          localStringBuilder = new StringBuilder(str6);
          Object[] arrayOfObject2;
          if (paramUnreadNum.comment > 0)
          {
            arrayOfObject2 = new Object[2];
            Integer localInteger2 = Integer.valueOf(paramUnreadNum.comment);
            arrayOfObject2[0] = localInteger2;
            String str7 = getString(2131427380);
            arrayOfObject2[1] = str7;
          }
          for (str4 = String.format("%d %s", arrayOfObject2); ; str4 = "")
          {
            String str8 = str4;
            arrayOfString[j] = str8;
            i = paramUnreadNum.comment;
            if (i > 0)
            {
              Intent localIntent3 = new Intent("com.sina.weibo.action.COMMENTNEW");
              Intent localIntent4 = localIntent3.putExtra("NUM", i);
              sendBroadcast(localIntent3);
            }
            this.mNotifyID = j;
            break;
          }
        }
        while (!MainTabActivity.mPrefNotifyAt);
        String str9 = String.valueOf(arrayOfString[j]);
        localStringBuilder = new StringBuilder(str9);
        Object[] arrayOfObject3;
        if (paramUnreadNum.atmsg > 0)
        {
          arrayOfObject3 = new Object[2];
          Integer localInteger3 = Integer.valueOf(paramUnreadNum.atmsg);
          arrayOfObject3[0] = localInteger3;
          String str10 = getString(2131427379);
          arrayOfObject3[1] = str10;
        }
        for (str4 = String.format("%d %s", arrayOfObject3); ; str4 = "")
        {
          String str11 = str4;
          arrayOfString[j] = str11;
          i = paramUnreadNum.atmsg;
          if (i > 0)
          {
            Intent localIntent5 = new Intent("com.sina.weibo.action.ATNEW");
            Intent localIntent6 = localIntent5.putExtra("NUM", i);
            sendBroadcast(localIntent5);
          }
          this.mNotifyID = j;
          break;
        }
      }
      while (!MainTabActivity.mPrefNotifyMessage);
      String str12 = String.valueOf(arrayOfString[j]);
      localStringBuilder = new StringBuilder(str12);
      Object[] arrayOfObject4;
      if (paramUnreadNum.message > 0)
      {
        arrayOfObject4 = new Object[2];
        Integer localInteger4 = Integer.valueOf(paramUnreadNum.message);
        arrayOfObject4[0] = localInteger4;
        String str13 = getString(2131427381);
        arrayOfObject4[1] = str13;
      }
      for (str4 = String.format("%d %s", arrayOfObject4); ; str4 = "")
      {
        String str14 = str4;
        arrayOfString[j] = str14;
        i = paramUnreadNum.message;
        if (i > 0)
        {
          Intent localIntent7 = new Intent("com.sina.weibo.action.MESSAGENEW");
          Intent localIntent8 = localIntent7.putExtra("NUM", i);
          sendBroadcast(localIntent7);
        }
        this.mNotifyID = j;
        break;
      }
    }
    while (!MainTabActivity.mPrefNotifyFans);
    String str15 = String.valueOf(arrayOfString[j]);
    StringBuilder localStringBuilder = new StringBuilder(str15);
    Object[] arrayOfObject5;
    if (paramUnreadNum.newfans > 0)
    {
      arrayOfObject5 = new Object[2];
      Integer localInteger5 = Integer.valueOf(paramUnreadNum.newfans);
      arrayOfObject5[0] = localInteger5;
      String str16 = getString(2131427382);
      arrayOfObject5[1] = str16;
    }
    for (String str4 = String.format("%d %s", arrayOfObject5); ; str4 = "")
    {
      String str17 = str4;
      arrayOfString[j] = str17;
      i = paramUnreadNum.newfans;
      if (i > 0)
      {
        Intent localIntent9 = new Intent("com.sina.weibo.action.FANSNEW");
        Intent localIntent10 = localIntent9.putExtra("NUM", i);
        sendBroadcast(localIntent9);
      }
      this.mNotifyID = j;
      break;
    }
  }

  private void setMessageBox(String paramString, int paramInt)
  {
    String str1 = String.valueOf(paramString);
    StringBuilder localStringBuilder = new StringBuilder(str1);
    String str2 = getString(2131427384);
    String str3 = str2;
    setNotifyType(str3, paramInt);
  }

  private void setNotifyType(int paramInt1, String paramString, int paramInt2)
  {
    Intent localIntent1 = new Intent();
    Context localContext = getApplicationContext();
    Intent localIntent2 = localIntent1.setClass(localContext, MainTabActivity.class);
    Notification localNotification;
    switch (this.mNotifyID)
    {
    default:
      PendingIntent localPendingIntent = PendingIntent.getActivity(this, 0, localIntent2, 0);
      localNotification = new Notification();
      Uri localUri = Uri.parse("android.resource://com.sina.weibo/raw/notificationsound");
      localNotification.flags = 16;
      localNotification.icon = paramInt1;
      if (SettingsPref.isAudioOn(this))
      {
        localNotification.defaults = 4;
        localNotification.sound = localUri;
      }
      if (paramInt2 != -1)
        localNotification.number = paramInt2;
      if (MainTabActivity.mPrefVibrator)
      {
         tmp143_142 = null;
        tmp143_142[0] = 80L;
         tmp149_143 = tmp143_142;
        tmp149_143[1] = 80L;
        Object localObject = tmp149_143;
        localNotification.vibrate = localObject;
      }
      localNotification.tickerText = paramString;
      String str = getString(2131427347);
      localNotification.setLatestEventInfo(this, str, paramString, localPendingIntent);
      switch (this.mNotifyID)
      {
      default:
      case 0:
      case 1:
      case 3:
      case 2:
      case 4:
      }
    case 0:
    case 1:
    case 3:
    case 2:
    case 4:
    }
    while (true)
    {
      this.mNotifyID = -1;
      return;
      Intent localIntent3 = localIntent2.setAction("sina.weibo.action.UPDATEHOME");
      break;
      Intent localIntent4 = localIntent2.setAction("sina.weibo.action.UPDATECOMMENT");
      break;
      Intent localIntent5 = localIntent2.setAction("sina.weibo.action.UPDATEAT");
      break;
      Intent localIntent6 = localIntent2.setAction("sina.weibo.action.UPDATEMESSAGE");
      break;
      Intent localIntent7 = localIntent2.setAction("sina.weibo.action.UPDATEFANS");
      break;
      this.ntfmngr.notify(10000, localNotification);
      continue;
      this.ntfmngr.notify(10001, localNotification);
      continue;
      this.ntfmngr.notify(10003, localNotification);
      continue;
      this.ntfmngr.notify(10002, localNotification);
      continue;
      this.ntfmngr.notify(10004, localNotification);
    }
  }

  private void setNotifyType(String paramString, int paramInt)
  {
    setNotifyType(2130837969, paramString, paramInt);
  }

  public IBinder onBind(Intent paramIntent)
  {
    if (paramIntent.getAction().equals("sina.weibo.action.BACKGROUND"))
      if (this.binder == null)
      {
        WeiboRemoteSerivcePoxy localWeiboRemoteSerivcePoxy1 = new WeiboRemoteSerivcePoxy(this);
        this.binder = localWeiboRemoteSerivcePoxy1;
      }
    for (WeiboRemoteSerivcePoxy localWeiboRemoteSerivcePoxy2 = this.binder; ; localWeiboRemoteSerivcePoxy2 = null)
      return localWeiboRemoteSerivcePoxy2;
  }

  public void onCreate()
  {
    super.onCreate();
    String str = getCacheDir().getPath();
    this.mCacheDir = str;
    User localUser1 = Utils.loadUserFile(this.mCacheDir);
    this.mUser = localUser1;
    if (this.mUser == null)
    {
      User localUser2 = StaticInfo.mUser;
      this.mUser = localUser2;
    }
    if (this.mUser == null)
      stopSelf();
    while (true)
    {
      IntentFilter localIntentFilter = new IntentFilter();
      localIntentFilter.addAction("com.sina.weibo.action.SWITCHUSER");
      localIntentFilter.addAction("sina.weibo.action.UPDATED");
      localIntentFilter.addAction("sina.weibo.action.BACKGROUND");
      localIntentFilter.addAction("sina.weibo.action.SETTING");
      localIntentFilter.addAction("sina.weibo.action.NOUSER");
      BroadcastReceiver localBroadcastReceiver = this.mReceiver;
      Intent localIntent = registerReceiver(localBroadcastReceiver, localIntentFilter);
      this.mTaskFree = 1;
      return;
      NotificationManager localNotificationManager = (NotificationManager)getSystemService("notification");
      this.ntfmngr = localNotificationManager;
    }
  }

  public void onDestroy()
  {
    this.mCheckStatusHandler.removeMessages(0);
    delNotify();
    BroadcastReceiver localBroadcastReceiver = this.mReceiver;
    unregisterReceiver(localBroadcastReceiver);
    super.onDestroy();
  }

  public void onStart(Intent paramIntent, int paramInt)
  {
    if (paramIntent == null);
    while (true)
    {
      return;
      String str1 = paramIntent.getStringExtra("username");
      this.mUsername = str1;
      String str2 = paramIntent.getStringExtra("password");
      this.mPassword = str2;
      refresh_status();
    }
  }

  public void refresh_status()
  {
    if ((this.mTaskFree) && (MainTabActivity.mPrefAutoCheck) && (!this.mUsername.equals("")) && (!this.mPassword.equals("")))
    {
      CheckStatusTask localCheckStatusTask = new CheckStatusTask(null);
      Void[] arrayOfVoid = new Void[0];
      AsyncTask localAsyncTask = localCheckStatusTask.execute(arrayOfVoid);
    }
    while (true)
    {
      return;
      CheckStatusHandler localCheckStatusHandler = this.mCheckStatusHandler;
      long l = MainTabActivity.mPrefInterval;
      localCheckStatusHandler.next(l);
    }
  }

  class CheckStatusHandler extends Handler
  {
    CheckStatusHandler()
    {
    }

    public void handleMessage(Message paramMessage)
    {
      WeiboEventService.this.refresh_status();
    }

    public void next(long paramLong)
    {
      removeMessages(0);
      Message localMessage = obtainMessage(0);
      boolean bool = sendMessageDelayed(localMessage, paramLong);
    }
  }

  class CheckStatusTask extends AsyncTask<Void, Void, UnreadNum>
  {
    private CheckStatusTask()
    {
    }

    protected UnreadNum doInBackground(Void[] paramArrayOfVoid)
    {
      Object localObject1 = null;
      try
      {
        if (WeiboEventService.this.mUser == null)
        {
          WeiboEventService localWeiboEventService1 = WeiboEventService.this;
          RPCHelper localRPCHelper1 = RPCHelper.getInstance(WeiboEventService.this.getApplication());
          String str1 = WeiboEventService.this.mUsername;
          String str2 = WeiboEventService.this.mPassword;
          User localUser1 = localRPCHelper1.login(str1, str2);
          localWeiboEventService1.mUser = localUser1;
          if ((WeiboEventService.this.mUser.gsid != null) && (WeiboEventService.this.mUser.uid != null));
        }
        label247: for (Object localObject2 = null; ; localObject2 = localObject1)
        {
          return localObject2;
          List localList = AccountHelper.loadAccounts(WeiboEventService.this);
          Account localAccount = new Account();
          String str3 = WeiboEventService.this.mUsername;
          localAccount.user = str3;
          String str4 = WeiboEventService.this.mPassword;
          localAccount.pass = str4;
          String str5 = WeiboEventService.this.mUser.nick;
          localAccount.nick = str5;
          AccountHelper.addOrSortAccount(localList, localAccount);
          AccountHelper.saveAccounts(WeiboEventService.this, localList);
          User localUser2 = WeiboEventService.this.mUser;
          String str6 = WeiboEventService.this.mCacheDir;
          WeiboEventService localWeiboEventService2 = WeiboEventService.this;
          Utils.saveUserFile(localUser2, str6, localWeiboEventService2);
          RPCHelper localRPCHelper2 = RPCHelper.getInstance(WeiboEventService.this.getApplication());
          User localUser3 = WeiboEventService.this.mUser;
          UnreadNum localUnreadNum = localRPCHelper2.getUnreadNum(localUser3);
          localObject1 = localUnreadNum;
        }
      }
      catch (Exception localException)
      {
        break label247;
      }
    }

    protected void onPostExecute(UnreadNum paramUnreadNum)
    {
      if (StaticInfo.mUser == null);
      while (true)
      {
        return;
        WeiboEventService.this.dispatchMessage(paramUnreadNum);
        WeiboEventService.this.mTaskFree = 1;
        WeiboEventService.CheckStatusHandler localCheckStatusHandler = WeiboEventService.this.mCheckStatusHandler;
        long l = MainTabActivity.mPrefInterval;
        localCheckStatusHandler.next(l);
      }
    }

    protected void onPreExecute()
    {
      WeiboEventService.this.mTaskFree = 0;
    }

    protected void onProgressUpdate(Void[] paramArrayOfVoid)
    {
    }
  }
}

/* Location:           D:\Program Files\eclipse\apktool-r01-3\新浪微博\classes.dex.dex2jar.jar
 * Qualified Name:     com.sina.weibo.WeiboEventService
 * JD-Core Version:    0.6.0
 */